package com.jk.admin.service;


import com.jk.admin.dao.CouponDao;
import com.jk.admin.entity.Coupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CouponService {

    @Autowired
    private CouponDao couponDao;


    public List<Coupon> query() {
        List<Coupon> list = couponDao.query();
        return list;
    }

    public void delete(String id) {
        couponDao.delete(id);
    }

    public void overdueCoupon(String id) {
        couponDao.overdueCoupon(id);
    }

    public void insertCoupon(Coupon coupon) {
        String[] split = coupon.getCoupon_startDate().split("-");
        String id="";
        for (int i = 0; i < split.length; i++) {
            id+=split[i];
        }
        Date date = new Date();
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        long time = date.getTime();
        id+=time+"";
        coupon.setCoupon_id(id);
        couponDao.insertCoupon(coupon);
    }

}
